﻿using System;
using System.Globalization;
using System.Windows.Data;
using Poet.ViewModels;
using System.Linq;

namespace Poet.Converters
{
    class SyntaxToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || string.IsNullOrEmpty(value.ToString())) return null;
            return DocumentViewModel.Syntaxes.FirstOrDefault(s => s.Name.Contains(value.ToString()));
        }
    }
}
